<!DOCTYPE html>
<html xmlns:v-on="http://www.w3.org/1999/xhtml">

	<head>
		<meta charset="utf-8" />
		<title>v-on:keydown</title>
		<script src="js/vuejs-2.5.16.js"></script>
	</head>

	<body>
		<div id="app">
			Vue:<input type="text" v-on:keydown="fun($event)">
			<hr/>
			传统JS：<input type="text"  onkeydown="showKeyCode()"/>
		</div>
	</body>
	<script>
		new Vue({
			el:"#app",
			methods:{
			    fun:function(event){
                    var keyCode = event.keyCode;
                    if(keyCode < 48  || keyCode > 57){
                        event.preventDefault();
                    }
				}
			}
		});


		function showKeyCode(){
			var keyCode = event.keyCode;
			if(keyCode < 48  || keyCode > 57){
				event.preventDefault();
			}
		}
	</script>
	
	

</html>